using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace minega
{
	public static class Neighbour
	{
		public static byte UL = 0,
			U = 1,
			UR = 2,
			L = 3,
			R = 4,
			DL = 5,
			D = 6,
			DR = 7;
	}

	public static class NeighbourPos
	{
		public static Point GetNeighbour(byte nb, int cellX, int cellY)
		{
			if (nb == Neighbour.UL)
			{
				cellX--;
				cellY--;
			}
			else if (nb == Neighbour.U)
			{
				cellY--;
			}
			else if (nb == Neighbour.UR)
			{
				cellX++;
				cellY--;
			}
			else if (nb == Neighbour.L)
			{
				cellX--;
			}
			else if (nb == Neighbour.R)
			{
				cellX++;
			}
			else if (nb == Neighbour.DL)
			{
				cellX--;
				cellY++;
			}
			else if (nb == Neighbour.D)
			{
				cellY++;
			}
			else if (nb == Neighbour.DR)
			{
				cellX++;
				cellY++;
			}
			else
			{
				return new Point(-1, -1);
			}
			
			return new Point(cellX, cellY);
		}

        public static CellPos GetNeighbour2(byte nb, UInt32 cellX, UInt32 cellY, UInt32 width, UInt32 height)
        {
            if (nb == Neighbour.UL)
            {
                if ((cellX == 0) || (cellY == 0))
                    return null;
                return new CellPos(cellX - 1, cellY - 1);
            }
            else if (nb == Neighbour.U)
            {
                if (cellY == 0)
                    return null;
                return new CellPos(cellX, cellY - 1);
            }
            else if (nb == Neighbour.UR)
            {
                if ((cellY == 0) || (cellX == width - 1))
                    return null;
                return new CellPos(cellX + 1, cellY - 1);
            }
            else if (nb == Neighbour.L)
            {
                if (cellX == 0)
                    return null;
                return new CellPos(cellX - 1, cellY);
            }
            else if (nb == Neighbour.R)
            {
                if (cellX == width - 1)
                    return null;
                return new CellPos(cellX + 1, cellY);
            }
            else if (nb == Neighbour.DL)
            {
                if ((cellX == 0) || (cellY == height - 1))
                    return null;
                return new CellPos(cellX - 1, cellY + 1);
            }
            else if (nb == Neighbour.D)
            {
                if (cellY == height - 1)
                    return null;
                return new CellPos(cellX, cellY + 1);
            }
            else if (nb == Neighbour.DR)
            {
                if ((cellY == height - 1) || (cellX == width - 1))
                    return null;
                return new CellPos(cellX + 1, cellY + 1);
            }
            return null;
        }
	}
}
